package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.service.wx.WxSearchService;
import com.cskaoyan.util.UserIdUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LY
 * @since 2022/06/09 16:34
 */
@RestController
@RequestMapping("wx/search")
public class WxSearchController {
    @Autowired
    WxSearchService wxSearchService;

    @GetMapping("index")
    public BaseRespVo index(){
        return BaseRespVo.ok(wxSearchService.index());
    }

    @GetMapping("helper")
    public BaseRespVo helper(String keyword){
        return BaseRespVo.ok(wxSearchService.helper(keyword));
    }

    @PostMapping("clearhistory")
    public BaseRespVo clearHistory(){
        Integer userId = null;
        try {
            userId = UserIdUtil.getUserIdFromSubjectThrowException();
        }catch (Exception e){
            return BaseRespVo.unlogin();
        }
        wxSearchService.clearHistoryKeyword(userId);
        return BaseRespVo.ok();
    }

}
